package edu.mis.modules.goods;

import com.jfinal.aop.Before;
import com.jfinal.core.Controller;

import edu.mis.model.Goods;

public class GoodsController extends Controller {
	private GoodsService service = new GoodsService();
	
	public void index() {
		render("goods.html");
	}
	
	public void list() {
		setAttr("data", service.findAllGoods());
		renderJson();
	}
	
	@Before(GoodsValidator.class)
	public void save() {
		Goods goods = getModel(Goods.class, "");
		if (goods.getId() == null) //添加
			setAttr("result", service.saveGoods(goods));
		else //修改
			setAttr("result", service.updateGoods(goods));
		renderJson();
	}
	
	public void delete() {
		Integer id = getParaToInt("id");
		setAttr("result", id != null && service.deleteById(id));
		renderJson();
	}
	
}
